//
//  PPScaleHelp.swift
//  XiaoHongYi
//
//  Created by 杨东宝 on 2020/5/5.
//  Copyright © 2020 杨东宝. All rights reserved.
//

import UIKit


public let DIMENSION_FONT_OF_SIZE:((CGFloat) -> UIFont ) = { (size :CGFloat) -> UIFont in
    
    return PPScaleHelp.sharedInstance.systemFontOfSize(size:size)
    
}
public let DIMENSION_BoldFONT_OF_SIZE:((CGFloat) -> UIFont ) = { (size :CGFloat) -> UIFont in
    
    return PPScaleHelp.sharedInstance.systemBoldFontOfSize(size: size)
    
}
public let DIMENSION_VALUE:((CGFloat) -> CGFloat ) = { (value :CGFloat) -> CGFloat in
    
    return PPScaleHelp.sharedInstance.dimensionValue(value:value)
    
}
class PPScaleHelp: NSObject {

    // 创建单例
       static let sharedInstance = PPScaleHelp()
       // 设置初始化方法为私有，防止报错
       private override init() {
           
       }
    
    func dimensionValue(value:CGFloat) -> CGFloat {
        
        self.factor() * value;
        
    }

    func systemFontOfSize(size:CGFloat) -> UIFont {
        
        var realSize:CGFloat = size
        
        if kIPHONE4_DEV || kIPHONE5_DEV {
                realSize = size - 1;
               }else if(kIPHONE6s_DEV || kIPHONEX_DEV){
                   
                  realSize = size;
               }else{
                  realSize = size + 1;
                   
          }
        return UIFont.systemFont(ofSize: realSize)
        
    }
    
    func systemBoldFontOfSize(size:CGFloat) -> UIFont {
        
        var realSize:CGFloat = size
        
        if kIPHONE4_DEV || kIPHONE5_DEV {
                realSize = size - 1;
               }else if(kIPHONE6s_DEV || kIPHONEX_DEV){
                   
                  realSize = size;
               }else{
                  realSize = size + 1;
                   
          }
         return  UIFont.boldSystemFont(ofSize: realSize)

    }
    
    func factor() -> CGFloat {
        var factor: CGFloat = 1.0
        
        if kIPHONE4_DEV || kIPHONE5_DEV {
            factor = 320.0/375.0
        }else if(kIPHONE6s_DEV || kIPHONEX_DEV){
            
            factor = 1.0
        }else{
            factor = 414.0/375.0
            
        }
        return factor
    }

}
